// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_FA_ASSETS
// * CreateDate    : 2013-08-28 11:00:55
// * Creater       : CodeSmith
// * LastChangeDate: 2013-08-28 11:00:55
// * LastChanger   : 2013-08-28 11:00:55
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;

namespace ESOL.Business.Fa
{
/// <summary>
    /// FaAssets
    /// </summary>
    public partial class FaAssetsBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objFaAssetsEntity">Entity</param>
        /// <returns>Entity</returns>
        public static FaAssetsEntity GetFaAssets(FaAssetsEntity objFaAssetsEntity)
        {
            return DataAccess.SelectSingle<FaAssetsEntity>(objFaAssetsEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objFaAssetsEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertFaAssets(FaAssetsEntity objFaAssetsEntity)
        {
            return DataAccess.Insert(objFaAssetsEntity);
        }

        public static bool InsertFaAssets(List<FaAssetsEntity> objFaAssetsEntityList)
        {
            return DataAccess.Insert(objFaAssetsEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objFaAssetsEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateFaAssets(FaAssetsEntity objFaAssetsEntity)
        {
            return DataAccess.Update(objFaAssetsEntity);
        }

        public static bool UpdateFaAssets(List<FaAssetsEntity> objFaAssetsEntityList)
        {
            return DataAccess.Update<FaAssetsEntity>(objFaAssetsEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objFaAssetsEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteFaAssets(FaAssetsEntity objFaAssetsEntity)
        {
            return DataAccess.Delete(objFaAssetsEntity);
        }

        public static bool DeleteFaAssets(List<FaAssetsEntity> objFaAssetsEntityList)
        {
            return DataAccess.Delete<FaAssetsEntity>(objFaAssetsEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetFaAssetsAll()
        {
            return DataAccess.SelectAllDataSet<FaAssetsEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<FaAssetsEntity> GetFaAssetsAllList()
        {
            return DataAccess.SelectAll<FaAssetsEntity>();
        }
        #endregion

        public static string GetNextAssetCode(string typeCode)
        {
            string code = typeCode;
            string sql = "SELECT MAX(ASSET_CODE) AS ASSET_CODE FROM FA_ASSETS WHERE ASSET_CODE LIKE '" + typeCode + "%'";
            DataSet ds = DataAccess.SelectDataSet(sql);
            string currentCode = "";
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                if (string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ASSET_CODE"].ToString()) == false)
                {
                    currentCode = ds.Tables[0].Rows[0]["ASSET_CODE"].ToString();
                }
                else
                {
                    return typeCode + "00001";
                }
            }
            else
            {
                return typeCode + "00001";
            }
            code += (CommonFunctions.ToInt32(currentCode.Substring(3)) + 1).ToString().PadLeft(5, '0');
            return code;
        }

	}
	
	
}	

